#leco 836 xml test
import getpath
import os
from xml.etree import ElementTree# as ET 
# import xml.etree
def daq(filename):
    tree = ElementTree.parse(filename)
    samples = tree.getroot()
    sample_count = len(samples)
    # title=["name","o","n","m"]
    for i in range(sample_count):
        sample_set = samples[i]
        name = sample_set[1].attrib["Value"]
        parallel_nu = len(sample_set) - 6
        for j in range(parallel_nu):
            node=sample_set[6 + j]
            print(node,dir(node))
            o = node.find("Oxygen").attrib["Value"].split(" ")[0]
            n = node.find("Nitrogen").attrib["Value"].split(" ")[0]
            h = node.find("Hydrogen")
            if h is None:
                h = ""
            else:
                h = h.attrib["Value"].split(" ")[0]
            # h = sample_set[6 + j].find("Nitrogen").attrib["Value"].split(" ")[0]
            m = node.find("SampleMass").attrib["Value"].split(" ")[0]
            time = node.find("Data").attrib["Value"]
            print(name,o,n,m)
            print(time,len(time))
            # cmd = """insert into result(sampleid,m,LO,LN,time) values('%s','%s','%s','%s','%s')""" % (
            #     name, m, o, n, time)
            # self.sql_cmd(cmd)
if __name__=="__main__":
    fname=os.path.join(getpath.getpath(),"..","data","836.xml")
    daq(fname)
